<template lang="html">
  <div class="logins">
    <div class="banner12">
      <label id="fanhui" @click="back"><img src="../../static/img/return1.png" alt=""></label>
      <label>注册ONE</label>
    </div>
  <div class="bd">
      <form id="formLogin">
        <div class="username">
          <div><label v-verified="verifyError.reid"></label></div>
          <input type="text" v-verify.grow1="reid" v-model="reid" placeholder="账号">
        </div>
        <div class="password">
          <div><label v-verified="verifyError.repassword"></label></div>
          <input type="password" v-verify.grow1="repassword" v-model="repassword" placeholder="密码">
        </div>
        <div class="repassword">
          <div><label v-verified="verifyError.rerepassword"></label></div>
          <input type="password" v-verify.grow1="rerepassword" v-model="rerepassword" placeholder="再次输入密码">
        </div>
        <div class="email">
          <div><label v-verified="verifyError.reemail"></label></div>
          <input type="text" v-verify.grow1="reemail" v-model="reemail" placeholder="输入邮箱">
        </div>
        <div class="uname">
          <div><label v-verified="verifyError.rename"></label></div>
          <input type="text" v-verify.grow1="rename" v-model="rename" placeholder="昵称">
        </div>
        <div class="sub_zhu">
          <button type="button" class="submitBtn" @click='reginper()'>注册</button>
        </div>
      </form>
    </div>
    <div class="ft">
       <router-link to="/logins">已经有账号？马上登录</router-link>
    </div>
    <div id="mess" v-show='shows'>
      <div class="box">
        <p>{{ ress }}</p>
        <label @click='queding()'>确定</label>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import verify from "vue-verify-plugin";
Vue.use(verify);
export default {
  name: 'login',
  data() {
    return {
      shows: false,
      codes: '',
      ress: '',
      reid: "",
      rename: "",
      reemail: "",
      repassword: "",
      rerepassword: "",
    }
  },
  methods: {
    back() {
      history.back()
    },
    reginper() {
      if (this.$verify.check()) {
        //通过验证
        // console.log('成功！');
        this.axios.get('http://10.0.156.247:8888/regin?rename=' + this.rename + '&repassword=' + this.repassword + '&reid=' + this.reid + '&reemail=' + this.reemail).then(data => {
          this.shows=true;
          this.codes=data.data.code;
          if(data.data.code==1){
            this.ress='注册成功';
          }else{
            this.ress=data.data.res;
          }
        })
      }else{
        console.log('sb');
      }
    },
    queding(){
      if(this.codes==1){
        console.log('成功');
        this.shows=false;
        this.$router.push({
          path:'/logins'
        })
      }else{
        console.log('shibai');
        this.shows=false;
        this.$router.push({
          path:'/regins'
        })
      }
    }
  },
  created() {
    // location.reload();
  },
  verify: {
    reid: [
      "required",
      {
        test: function(val) {
          var pattern = /^[\w\u4e00-\u9fa5]{3,10}$/g
          if (val.length < 3) {
            return false;
          }else if(!pattern.test(val)){
            return false;
          }
          return true;
        },
        message: "请输入3-10个字母/汉字/数字/下划线"
      }
    ],
    rename: [
      "required",
      {
        test: function(val) {
          var pattern = /^[\w\u4e00-\u9fa5]{3,10}$/g
          if (val.length < 3) {
            return false;
          }else if(!pattern.test(val)){
            return false;
          }
          return true;
        },
        message: "请输入3-10个字母/汉字/数字/下划线"
      }
    ],
    reemail: [
      "required",
      {
        test: function(val) {
          var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
          if(!pattern.test(val)){
            return false;
          }
          return true;
        },
        message: "请输入正确的邮箱地址"
      }
    ],
    repassword: [
      "required",
      {
        test: function(val) {
          var pattern = /^\S{3,20}$/g
          if (val.length < 4) {
            return false;
          }else if(!pattern.test(val)){
            return false;
          }
          return true;
        },
        message: "请输入4-20个非空白字符"
      }
    ],
    rerepassword:[
      "required",
      {
        test: function(val) {
          if (val!== this.repassword) {
            return false;
          }
          return true;
        },
        message: "请确定两次密码一致"
      }
    ]
  },
  computed: {
    verifyError: function() {
      return this.$verify.$errors;
    }
  }
}
</script>

<style media="screen">
body {
  margin: 0;
  padding: 0;
}
</style>

<style lang="css" scoped>
*{
  margin:0;
  padding: 0;
}

.logins{
  height: 700px;
  position: relative;
  /*background: linear-gradient(to bottom,#562e37,#f17c67);*/
  background-image: url(../../static/img/regin.jpg);
  color: white;
}

.banner12{
  height: 2.5rem;
  /*background: white;*/
  line-height: 2.5rem;
  color: #646a58;
  font-size: 1.8rem;
  width: 100%;
  position:fixed;
  top: 0.6rem;
  left: 0;
}
#fanhui{
  position: absolute;
  height: 1.5rem;
  width: 0.9rem;
  /*background-image: url(../../static/img/return1.png);
  background-size: 15px,15px;*/
  top: 0.3rem;
  left: 0.9rem;
}
#fanhui>img{
  height: 1.5rem;
  width: 0.8rem;
}

.bd{
  position: absolute;
  top: 20%;
  left: 20%;
  width: 60%;
}
.username{
  /*margin-bottom: 0.9rem;*/
}
.username>input{
  height: 2.2rem;
  width: 18rem;
  border: none;
}
.username>div{
  height: 1.2rem;
  width: 100%;
  color:#b0171f;
  margin-bottom: 0.2rem;
  margin-top: 0.2rem;
}
.password>div{
  height: 1.2rem;
  width: 100%;
    color:#b0171f;
  margin-bottom: 0.2rem;
  margin-top: 0.2rem;
}
.password>input{
  height: 2.2rem;
  width: 18rem;
  border: none;
}
.repassword>div{
  height: 1.2rem;
  width: 100%;
  color:#b0171f;
  margin-bottom: 0.2rem;
  margin-top: 0.2rem;
}
.repassword>input{
  height: 2.2rem;
  width: 18rem;
  border: none;
}
.email>div{
  height: 1.2rem;
  width: 100%;
  color:#b0171f;
  margin-bottom: 0.2rem;
  margin-top: 0.2rem;
}
.email>input{
  height: 2.2rem;
  width: 18rem;
  border: none;
}
.uname>div{
  height: 1.2rem;
  width: 100%;
  color:#b0171f;
  margin-bottom: 0.2rem;
  margin-top: 0.2rem;
}
.uname>input{
  height: 2.2rem;
  width: 18rem;
  border: none;
}
.sub_zhu>button{
  margin-top: 2.0rem;
   height: 2rem;
   width: 4.5rem;
   border-radius: 5px;
   border: none;
   color: gray;
   font-size: 1.6rem;
}
.ft{
  position: absolute;
  top: 64%;
  left: 28%
}
.ft>a{
  color: white;
  font-size: 1.8rem;
  text-decoration: none;
}
#mess{
  height: 100%;
  width: 100%;
  background: rgba(128, 138, 135, 0.5);
  position: relative;
}
#mess>.box{
  width: 60%;
  height: 20%;
  margin: auto;
  background: white;
  position: absolute;
  top: 30%;
  left: 20%;
  border-radius: 15px;
  color:black;
  font-size: 2.5rem;
}
#mess>.box>p{
  margin: auto;
  margin-top: 1.0rem;
  margin-bottom: 3.0rem;
}
#mess>.box>label{
  display: inline-block;
  width: 6.0rem;
  height: 3rem;
  text-align: center;
  vertical-align: middle;
  background: #40e0d0;
  border-radius: 5px;
}
</style>
